package pos.data;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import pos.utils.UIDGenerator;

public class JDBCInscripcionDAO implements IInscripcionDAO{
	
	private Connection conn;
	
	public JDBCInscripcionDAO(){
		conn = ConnectionManager.getInstance().checkOut();
	}
	
	public JDBCInscripcionDAO(Connection conn){
		this.conn = conn;
	}

	@Override
	public void insertInscripcion(String idUsuario, String eventoid) {
		String sql = "INSERT INTO inscripciones ( OID, usuarioOID, eventoOID, aceptada) VALUES (?, ?, ?, ?) ";
        PreparedStatement stmt = null;
        boolean aux = true;
        String oid = UIDGenerator.getInstance().getKey(); 

        try {
            stmt = conn.prepareStatement(sql);

            stmt.setString(1, oid);
            stmt.setString(2, idUsuario);
            stmt.setString(3, eventoid);
            stmt.setInt(4, 0);
            
            stmt.executeUpdate();

        } catch (SQLException e) {
            System.out.println("Message: " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("ErrorCode: " + e.getErrorCode());
        } finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            } catch (SQLException e) {
            }
        }
		
	}
}
